package com.sg.fileService.service.impl;

import org.springframework.stereotype.Service;

import com.sg.common.exception.BaseBusinessException;
import com.sg.fileService.common.ErrorCode;
import com.sg.fileService.entity.FileTypeConfig;

@Service
public class AdvancedUploadStrategy extends BaseFileUploadServiceImpl{
	@Override
	protected void doEncoder(String sourcePath, FileTypeConfig fileConfig) throws BaseBusinessException{
		BaseFileUploadServiceImpl fileUploadServiceImpl = uploadServiceStrategy(fileConfig);
		fileUploadServiceImpl.doEncoder(sourcePath, fileConfig);
	}
	
	/**
	 * 根据文件类型，选择不同的处理类
	 * @param fileConfig
	 * @return
	 * @throws BaseBusinessException
	 */
	private BaseFileUploadServiceImpl uploadServiceStrategy(FileTypeConfig fileConfig) throws BaseBusinessException{
		 //进行文件处理
        if(fileConfig.getTypePath().equals("video")){
        	//视频文件处理
        	return new VideoUploadServiceImpl();
        }else if(fileConfig.getTypePath().equals("audio")){
        	//音频文件处理
        	return new AudioUploadServiceImpl();
        }else if(fileConfig.getTypePath().equals("image")){
        	//图片文件处理
        	return new ImageUploadServiceImpl();
        }else {
        	throw new BaseBusinessException(ErrorCode.FILE_FORMAT_NOT_FONT);
        }
	}

}
